/**
 * FacebookJsonRestClientBean.java
 * 
 * Created on Nov 9, 2007 at 1:00:42 PM
 */
package mobiled.bascule.facebook.client.impl;

import mobiled.bascule.facebook.FacebookAppConfig;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import com.facebook.api.FacebookJsonRestClient;

/**
 * A {@link FactoryBean} of {@link FacebookJsonRestClient}.
 *  
 * @author <a href="alexei.guevara@gmail.com">Alexei Guevara</>
 * @version $Revision:$ updated on $Date:$ by $Author:$
 */
public class FacebookJsonRestClientBean implements FactoryBean {
    
    private final FacebookAppConfig myFbAppConfig;
    
    private FacebookJsonRestClient myFbJsonRestClient;
    
    @Autowired
    public FacebookJsonRestClientBean( FacebookAppConfig theFbAppConfig ) {
	myFbAppConfig = theFbAppConfig;
    }

    public Object getObject() throws Exception {
	if (myFbJsonRestClient==null) {
	    myFbJsonRestClient = new FacebookJsonRestClient( myFbAppConfig.getApiKey(), myFbAppConfig.getSecret() );
	}
	return myFbJsonRestClient;
    }

    /**
     * {@inheritDoc}
     */
    public Class<FacebookJsonRestClient> getObjectType() {
	return FacebookJsonRestClient.class;
    }

    /**
     * {@inheritDoc}
     */
    public boolean isSingleton() {
	return true;
    }

}
